import React, { memo, useState, useEffect } from "react";
import { Link } from "react-router-dom";
import { Menu } from "antd";
import { SettingOutlined } from "@ant-design/icons";

const { SubMenu } = Menu;

const LeftSider = ({ theme, mode = "inline", style, pathname }) => {
  const [current, setCurrent] = useState("profile");

  function handleClick(e) {
    console.log(e);
    return setCurrent(e.key);
  }

  useEffect(() => {
    const currentRoute = pathname.split('/')[1];
    console.log('currentRoute', currentRoute)
    setCurrent(currentRoute);
  }, [pathname]);

  return (
    <Menu
      onClick={handleClick}
      selectedKeys={[current]}
      defaultOpenKeys={["baseinfo"]}
      mode={mode}
      theme={theme}
      style={style}
    >
      {/* 基础信息 */}
      <SubMenu key="baseinfo" icon={<SettingOutlined />} title="基础信息">
        <Menu.Item key="profile">
          <Link to="/profile">企业信息</Link>
        </Menu.Item>
      </SubMenu>
      {/* 成员管理 */}
      <Menu.Item key="member" icon={<SettingOutlined />}>
        <Link to="/member">成员管理</Link>
      </Menu.Item>
      {/* 第三方信息管理 */}
      <Menu.Item key="third" icon={<SettingOutlined />}>
        <Link to="/third">第三方信息管理</Link>
      </Menu.Item>
      {/* 权限管理 */}
      <SubMenu key="auths" icon={<SettingOutlined />} title="权限管理">
        <Menu.Item key="company">
          <Link to="/company">企业权限</Link>
        </Menu.Item>
        <Menu.Item key="project">
          <Link to="/project">项目权限</Link>
        </Menu.Item>
        <Menu.Item key="special">
          <Link to="/special">专项测试</Link>
        </Menu.Item>
        <Menu.Item key="release">
          <Link to="/release">发布管理</Link>
        </Menu.Item>
      </SubMenu>
      {/* 日志管理 */}
      <SubMenu key="logs" icon={<SettingOutlined />} title="日志管理">
        <Menu.Item key="hanldeLog">
          <Link to="/hanldeLog">操作日志</Link>
        </Menu.Item>
        <Menu.Item key="systemLog">
          <Link to="/systemLog">系统日志</Link>
        </Menu.Item>
      </SubMenu>
    </Menu>
  );
};

export default memo(LeftSider);
